<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 线程池完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .timeline-dot {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 1rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        
        .first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #667eea;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 4rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-7xl font-bold mb-6">
                Java 线程池
                <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">完全指南</span>
            </h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto leading-relaxed opacity-95">
                深入理解 Java 并发编程的核心工具，掌握高性能应用的关键技术
            </p>
            <div class="mt-10 flex justify-center space-x-8">
                <div class="text-center">
                    <i class="fas fa-layer-group text-4xl mb-2"></i>
                    <p class="text-lg">5 种线程池</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-rocket text-4xl mb-2"></i>
                    <p class="text-lg">性能优化</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-shield-alt text-4xl mb-2"></i>
                    <p class="text-lg">最佳实践</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6 bg-white">
        <div class="max-w-4xl mx-auto">
            <div class="prose prose-lg">
                <p class="text-xl leading-relaxed text-gray-700">
                    <span class="first-letter">J</span>ava 并发库中的线程池是 Java 线程管理的核心工具之一，主要通过 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">java.util.concurrent</code> 包中的 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">ExecutorService</code> 接口和它的各种实现类来提供。使用线程池的主要目的是为了提高系统的性能和资源利用率，避免频繁地创建和销毁线程带来的开销。
                </p>
            </div>
        </div>
    </section>

    <!-- Thread Pool Types Section -->
    <section class="py-16 px-6 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-16 text-gradient">线程池类型详解</h2>
            
            <!-- FixedThreadPool -->
            <div class="mb-12 card-hover bg-white rounded-2xl p-8 shadow-lg">
                <div class="flex items-center mb-6">
                    <i class="fas fa-th text-4xl feature-icon mr-4"></i>
                    <h3 class="text-3xl font-bold">1. FixedThreadPool</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">
                            <i class="fas fa-star mr-2"></i>特点
                        </h4>
                        <p class="text-gray-700 leading-relaxed">
                            <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">FixedThreadPool</code> 是一个有固定数量线程的线程池。池中的线程数量固定，不会因为任务的增多而增加线程数量。新任务到来时，如果有空闲线程，则会立即执行；如果所有线程都在忙，任务会进入等待队列。
                        </p>
                    </div>
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">
                            <i class="fas fa-bullseye mr-2"></i>适用场景
                        </h4>
                        <p class="text-gray-700 leading-relaxed">
                            适合任务量已知且不太变化的场景，比如处理常规的后台任务，保证固定的并发量。
                        </p>
                    </div>
                </div>
                <div class="mt-6 grid md:grid-cols-2 gap-4">
                    <div class="bg-green-50 p-4 rounded-lg">
                        <h5 class="font-semibold text-green-800 mb-2">
                            <i class="fas fa-check-circle mr-2"></i>优点
                        </h5>
                        <p class="text-green-700">控制并发线程数，避免因线程数量过多导致的系统资源消耗过大。</p>
                    </div>
                    <div class="bg-red-50 p-4 rounded-lg">
                        <h5 class="font-semibold text-red-800 mb-2">
                            <i class="fas fa-times-circle mr-2"></i>缺点
                        </h5>
                        <p class="text-red-700">线程数量固定，当任务堆积时，可能导致等待时间较长。</p>
                    </div>
                </div>
            </div>

            <!-- CachedThreadPool -->
            <div class="mb-12 card-hover bg-white rounded-2xl p-8 shadow-lg">
                <div class="flex items-center mb-6">
                    <i class="fas fa-expand-arrows-alt text-4xl feature-icon mr-4"></i>
                    <h3 class="text-3xl font-bold">2. CachedThreadPool</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">
                            <i class="fas fa-star mr-2"></i>特点
                        </h4>
                        <p class="text-gray-700 leading-relaxed">
                            <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">CachedThreadPool</code> 是一个会根据需要自动扩展的线程池。池中的线程数量没有上限，当有新任务到来时，如果没有空闲线程，则会创建新的线程来执行任务；如果线程空闲超过 60 秒，则会被销毁。
                        </p>
                    </div>
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">
                            <i class="fas fa-bullseye mr-2"></i>适用场景
                        </h4>
                        <p class="text-gray-700 leading-relaxed">
                            适用于任务量大且任务执行时间较短的场景，如处理瞬时的并发请求。
                        </p>
                    </div>
                </div>
                <div class="mt-6 grid md:grid-cols-2 gap-4">
                    <div class="bg-green-50 p-4 rounded-lg">
                        <h5 class="font-semibold text-green-800 mb-2">
                            <i class="fas fa-check-circle mr-2"></i>优点
                        </h5>
                        <p class="text-green-700">灵活的线程管理，能够快速响应大量短期任务。</p>
                    </div>
                    <div class="bg-red-50 p-4 rounded-lg">
                        <h5 class="font-semibold text-red-800 mb-2">
                            <i class="fas fa-times-circle mr-2"></i>缺点
                        </h5>
                        <p class="text-red-700">如果任务持续增长，可能会导致创建过多线程，消耗大量系统资源。</p>
                    </div>
                </div>
            </div>

            <!-- SingleThreadExecutor -->
            <div class="mb-12 card-hover bg-white rounded-2xl p-8 shadow-lg">
                <div class="flex items-center mb-6">
                    <i class="fas fa-stream text-4xl feature-icon mr-4"></i>
                    <h3 class="text-3xl font-bold">3. SingleThreadExecutor</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">
                            <i class="fas fa-star mr-2"></i>特点
                        </h4>
                        <p class="text-gray-700 leading-relaxed">
                            <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">SingleThreadExecutor</code> 是一个只有一个线程的线程池。所有任务会按照提交顺序依次执行，任务不会并行执行。
                        </p>
                    </div>
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">
                            <i class="fas fa-bullseye mr-2"></i>适用场景
                        </h4>
                        <p class="text-gray-700 leading-relaxed">
                            适合需要顺序执行任务的场景，保证任务按提交顺序执行，例如日志记录、订单处理等。
                        </p>
                    </div>
                </div>
                <div class="mt-6 grid md:grid-cols-2 gap-4">
                    <div class="bg-green-50 p-4 rounded-lg">
                        <h5 class="font-semibold text-green-800 mb-2">
                            <i class="fas fa-check-circle mr-2"></i>优点
                        </h5>
                        <p class="text-green-700">保证任务的顺序执行，简单易用。</p>
                    </div>
                    <div class="bg-red-50 p-4 rounded-lg">
                        <h5 class="font-semibold text-red-800 mb-2">
                            <i class="fas fa-times-circle mr-2"></i>缺点
                        </h5>
                        <p class="text-red-700">单线程处理，性能瓶颈明显，不能应对大量并发任务。</p>
                    </div>
                </div>
            </div>

            <!-- ScheduledThreadPool -->
            <div class="mb-12 card-hover bg-white rounded-2xl p-8 shadow-lg">
                <div class="flex items-center mb-6">
                    <i class="fas fa-clock text-4xl feature-icon mr-4"></i>
                    <h3 class="text-3xl font-bold">4. ScheduledThreadPool</h3>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="text-xl font-semibold mb-3 text-purple-700">